var index = 0
var currentPage = 0
/*
currentSearch == -1 全部搜索
currentSearch == -2 条件搜索/
 */
var currentSearch = -1

/*
currentModal == 0 申请modal申请人
currentModal == 1 表格人员
currentModal == 2 审核人/
 */
var currentModal = 0
/*/
活动管理权限管理
 */
var flag_temporaryProjectManage = true
$(document).ready(function () {
    addTimeOutAction()
    getAllTemporaryApply()
    initInterfaceWithPermission()
    /*
    左箭头/
     */
    $('.path-arrow-left').on('click', function () {
        $('#temporaryProjectUpdatePanel').addClass('hidden')
        $('#temporaryProjectRecordPanel').removeClass('hidden')
        getAllTemporaryApply()
    })
    /*
      选择one员工/
       */
    $('.selectOneStaff-department-li img').on('click', function () {
        if($(this).parent().find('.hidden').length == 0){
            $(this).parent().find('.selectOneStaff-staff-ul').addClass('hidden')
            $(this).parent().find('.departmentName-img').attr('src', 'imgs/addition.png')
        }else{
            $(this).parent().find('.selectOneStaff-staff-ul').removeClass('hidden')
            $(this).parent().find('.departmentName-img').attr('src', 'imgs/offline.png')
        }
    })
    $('.selectOneStaff-department-li .departmentName-span').on('click', function () {
        if($(this).parent().find('.hidden').length == 0){
            $(this).parent().find('.selectOneStaff-staff-ul').addClass('hidden')
            $(this).parent().find('.departmentName-img').attr('src', 'imgs/addition.png')
        }else{
            $(this).parent().find('.selectOneStaff-staff-ul').removeClass('hidden')
            $(this).parent().find('.departmentName-img').attr('src', 'imgs/offline.png')
        }
    })
    /*
    按姓名搜索modal/
     */
    $('#myModal-selectOneStaff .modal-searchInput input').on('input propertychange', function () {
        if($(this).val() == ''){
            $('#form-selectOneStaff .selectOneStaff-staff-ul2').addClass('hidden')
            $('#form-selectOneStaff .selectOneStaff-department-ul').removeClass('hidden')
        }
    })
    /*
    补助和天数改变事件/
     */
    $('#temporaryProjectUpdatePanel .table-selfDefine').on('input', '.unitWage', function () {
        var unitWage = $(this).val()
        var days = $(this).parent().parent().find('.days').val()
        var sumWage = unitWage * days
        sumWage = sumWage.toFixed(2)
        $(this).parent().parent().find('.sumWage').text(sumWage)
    })
    $('#temporaryProjectUpdatePanel .table-selfDefine').on('input', '.days', function () {
        var days = $(this).val()
        var unitWage = $(this).parent().parent().find('.unitWage').val()
        var sumWage = unitWage * days
        sumWage = sumWage.toFixed(2)
        $(this).parent().parent().find('.sumWage').text(sumWage)
    })
    /*
   小计改变事件/
    */
    $('#temporaryProjectUpdatePanel .table-selfDefine').on('DOMNodeInserted', '.sumWage', function () {
        var tr = $('#temporaryProjectUpdatePanel .table-selfDefine .table-tr')
        var totalWage = 0
        for(var i = 0; i < tr.length; i++){
            if(tr.eq(i).find('.sumWage').text()){
                totalWage = parseFloat(totalWage) + parseFloat(tr.eq(i).find('.sumWage').text())
            }
        }
        totalWage = totalWage.toFixed(2)
        $('#temporaryProjectUpdatePanel-totalWage').text(totalWage)
    })
    /*
    搜索添加回车绑定事件/
     */
    $('#myModal-selectOneStaff .modal-searchInput input').on('keypress', function (event) {
        if(event.keyCode == '13'){
            searchOneByName_modal(this)
        }
    })
})

/*
权限初始化界面
 */
function initInterfaceWithPermission() {
    if($.inArray(11, JSON.parse(window.localStorage.permissions)) < 0){
        $('#head-delete').addClass('hidden')
        $('#head-modify').addClass('hidden')
        $('.temporaryProjectManager-update').addClass('hidden')
        $('.temporaryProjectManager-delete').addClass('hidden')
        flag_temporaryProjectManage = false;
    }
}

/*
获取所有申请记录/
 */
function getAllTemporaryApply(page_ = 0) {
    currentSearch = -1
    currentPage = page_
    var page = currentPage
    var sortFieldName = 'applyTime'
    var asc = 0
    var size = 10
    $.ajax({
        url: ipPort + '/temporaryProjectHeader/getAllByPage?page=' + page + '&sortFieldName='
            + sortFieldName + '&asc=' + asc + '&size=' + size,
        success:function (obj) {
            if(obj.code == 0){
                setTemporaryProjectTable(obj)
            }else {
                alert(obj.message)
            }
        },
        error:function (error) {
            console.log(error)
        }
    })
}
/*
通过状态搜索/
 */
function searchByStatus(page_ = 0) {
    currentSearch = -2
    currentPage = page_
    var sortFieldName = 'applyTime'
    var asc = 0
    var size = 10
    var startDate = '2000-01-01'
    var endDate = '2000-01-01'
    var applicantId = -1
    var status = $('#selectStatus-dropdownMenu').attr('value')
    $.ajax({
        url:ipPort + '/temporaryProjectHeader/getByApplicantAndStatusAndDateByPage?status=' + status + '&page=' + currentPage + '&sortFieldName='
            + sortFieldName + '&asc=' + asc + '&size=' + size + '&startDate=' + startDate + '&endDate=' + endDate + '&applicantId=' + applicantId,
        success:function (obj) {
            if(obj.code == 0){
                if(obj.data.numberOfElements == 0){
                    alert('无相关信息！')
                    setTemporaryProjectTable(obj)
                }else {
                    setTemporaryProjectTable(obj)
                }
            }else{
                alert(obj.message)
            }
        },
        error:function (error) {
            consle.log(error)
        }
    })
}
/*
设置申请表/
 */
function setTemporaryProjectTable(obj) {
    $('.currentPage').text(currentPage + 1)
    $('.totalPage').text(obj.data.totalPages)
    var id = $('.temporaryProjectManager-id')
    var applyUser = $('.temporaryProjectManager-applyUser')
    var operator = $('.temporaryProjectManager-operator')
    var department = $('.temporaryProjectManager-department')
    var workDate = $('.temporaryProjectManager-workDate')
    var applyTime = $('.temporaryProjectManager-applyTime')
    var status = $('.temporaryProjectManager-status')
    var update = $('.temporaryProjectManager-update').find('a')
    var delete_ = $('.temporaryProjectManager-delete').find('a')
    var tr = $('.table-tr')
    var length = obj.data.numberOfElements
    for(var i = 0; i < length; i++){
        tr.eq(i).removeClass('hidden')
        id.eq(i).text('')
        applyUser.eq(i).attr('value', '')
        applyUser.eq(i).text('')
        operator.eq(i).attr('value', '')
        operator.eq(i).text('')
        department.eq(i).attr('value', '')
        department.eq(i).text('')
        workDate.eq(i).text('')
        applyTime.eq(i).text('')
        status.eq(i).attr('value', '')
        status.eq(i).text('')
        update.eq(i).attr('onclick', 'setTemporaryProjectUpdatePanel(this)')
        update.eq(i).css('color', '#337ab7')
        update.eq(i).css('cursor', 'pointer')
        delete_.eq(i).attr('onclick', 'setMakeSureDeleteButtonValue(this)')
        delete_.eq(i).attr('data-toggle', 'modal')
        delete_.eq(i).attr('data-target', '#myModal-makeSureDelete')
        delete_.eq(i).css('color', '#337ab7')
        delete_.eq(i).css('cursor', 'pointer')

        id.eq(i).text(obj.data.content[i].id)
        applyUser.eq(i).attr('value', obj.data.content[i].applicant.id)
        applyUser.eq(i).text(obj.data.content[i].applicant.name)
        operator.eq(i).attr('value', obj.data.content[i].operator.id)
        operator.eq(i).text(obj.data.content[i].operator.name)
        department.eq(i).attr('value', obj.data.content[i].department.id)
        department.eq(i).text(obj.data.content[i].department.name)
        if(flag_temporaryProjectManage){
            workDate.eq(i).text(obj.data.content[i].date)
        }
        else{
            workDate.eq(i).text('******')
        }

        applyTime.eq(i).text(obj.data.content[i].applyTime)
        status.eq(i).attr('value', obj.data.content[i].status)
        if(obj.data.content[i].status == 0){
            status.eq(i).text('未审核')
        } else if(obj.data.content[i].status == 1){
            status.eq(i).text('通过')
            update.eq(i).removeAttr('onclick')
            update.eq(i).css('color', '#5A5A5A')
            update.eq(i).css('cursor', 'default')
            delete_.eq(i).removeAttr('onclick')
            delete_.eq(i).removeAttr('data-toggle')
            delete_.eq(i).removeAttr('data-target')
            delete_.eq(i).css('color', '#5A5A5A')
            delete_.eq(i).css('cursor', 'default')
        }else if(obj.data.content[i].status == 2){
            status.eq(i).text('未通过')
            update.eq(i).removeAttr('onclick')
            update.eq(i).css('color', '#5A5A5A')
            update.eq(i).css('cursor', 'default')
            delete_.eq(i).removeAttr('onclick')
            delete_.eq(i).removeAttr('data-toggle')
            delete_.eq(i).removeAttr('data-target')
            delete_.eq(i).css('color', '#5A5A5A')
            delete_.eq(i).css('cursor', 'default')
        }
    }
    for(var i = length; i < 10; i++){
        tr.eq(i).addClass('hidden')
    }
}
/*
设置修改界面Panel/
 */
function setTemporaryProjectUpdatePanel(thisObj) {
    $('#temporaryProjectUpdatePanel').removeClass('hidden')
    $('#temporaryProjectRecordPanel').addClass('hidden')

    $('#temporaryProjectUpdatePanel-makeTablePerson').attr('value', '')
    $('#temporaryProjectUpdatePanel-makeTablePerson').text('')
    $('#temporaryProjectUpdatePanel-workDate').val('')
    $('#temporaryProjectUpdatePanel-applyDepartment').attr('value', '')
    $('#temporaryProjectUpdatePanel-applyDepartment').val('')
    $('#temporaryProjectUpdatePanel-applyStaff').attr('value', '')
    $('#temporaryProjectUpdatePanel-applyStaff').val('')
    $('#temporaryProjectUpdatePanel-auditor').attr('value', '')
    $('#temporaryProjectUpdatePanel-auditor').val('')
    $('#temporaryProjectUpdatePanel-serviceCharge').val('')
    $('#temporaryProjectUpdatePanel-personNumber').text('')
    $('#temporaryProjectUpdatePanel-content').val('')
    $('#temporaryProjectUpdatePanel .table-selfDefine').find('.table-tr').remove()
    $('#temporaryProjectUpdatePanel-totalWage').text('')
    var id = $(thisObj).parent().parent().find('td').eq(0).text()
    $('#temporaryProjectUpdatePanel').attr('value', id)

    /*
    表格初始化5行/
     */
    index = 0
    for(var i = 0; i < 5; i++){
        index++
        var tbody = $('#temporaryProjectUpdatePanel .table-selfDefine tbody')
        var appendStr = "<tr class='table-tr'><td>" + index + "</td><td><input class='selectPerson' onclick='getAllStaff_one(1,this)' data-toggle='modal' data-target='#myModal-selectOneStaff'></td>" +
            "<td><input class='unitWage'></td><td><input class='days'></td><td class='sumWage'></td>" +
            "<td style='border-right: none'><a onclick='cleanRowApplyContent(this)'><img src='imgs/minus-r.png'></a></td></tr>"
        tbody.append(appendStr)
    }

    $.ajax({
        url: ipPort + '/temporaryProjectHeader/getById?id=' + id,
        success: function (obj) {
            if(obj.code == 0){
                $('#temporaryProjectUpdatePanel-makeTablePerson').attr('value', obj.data.operator.id)
                $('#temporaryProjectUpdatePanel-makeTablePerson').text(obj.data.operator.name)
                var workDateSplit = obj.data.date
                if(workDateSplit){
                    var workDate = new Date()
                    workDate.setFullYear(workDateSplit.split('-')[0], workDateSplit.split('-')[1] - 1, workDateSplit.split('-')[2])
                    $('#temporaryProjectUpdatePanel-workDate').val(workDate.toLocaleDateString())
                }else{
                    $('#temporaryProjectUpdatePanel-workDate').val('')
                }
                $('#temporaryProjectUpdatePanel-applyDepartment').attr('value', obj.data.department.id)
                $('#temporaryProjectUpdatePanel-applyDepartment').val(obj.data.department.name)

                $('#temporaryProjectUpdatePanel-applyStaff').attr('value', obj.data.applicant.id)
                $('#temporaryProjectUpdatePanel-applyStaff').val(obj.data.applicant.name)

                $('#temporaryProjectUpdatePanel-auditor').attr('value', obj.data.auditor.id)
                $('#temporaryProjectUpdatePanel-auditor').val(obj.data.auditor.name)

                $('#temporaryProjectUpdatePanel-serviceCharge').val(obj.data.serviceCharge)
                $('#temporaryProjectUpdatePanel-personNumber').text(obj.data.personNum)
                $('#temporaryProjectUpdatePanel-content').val(obj.data.content)
                var tbody = $('#temporaryProjectUpdatePanel .table-selfDefine tbody')
                for(var i = 0; i < obj.data.details.length; i++){
                    var tr = $('#temporaryProjectUpdatePanel .table-selfDefine tbody').find('.table-tr')
                    tr.eq(i).find('.selectPerson').attr('value', obj.data.details[i].user.id)
                    tr.eq(i).find('.selectPerson').val(obj.data.details[i].user.name)
                    tr.eq(i).find('.unitWage').val(obj.data.details[i].unitWage)
                    tr.eq(i).find('.days').val(obj.data.details[i].days)
                    tr.eq(i).find('.sumWage').text(obj.data.details[i].sumWage)
                    if(i == 4)break;
                }
                for(var i = 5; i < obj.data.details.length; i++){
                    index++
                    var tbody = $('#temporaryProjectUpdatePanel .table-selfDefine tbody')
                    var appendStr = "<tr class='table-tr'><td>" + index + "</td><td><input class='selectPerson' onclick='getAllStaff_one(1,this)' data-toggle='modal' data-target='#myModal-selectOneStaff'></td>" +
                        "<td><input class='unitWage'></td><td><input class='days'></td><td class='sumWage'></td>" +
                        "<td style='border-right: none'><a onclick='cleanRowApplyContent(this)'><img src='imgs/minus-r.png'></a></td></tr>"
                    tbody.append(appendStr)
                }
                for(var i = 5; i < obj.data.details.length; i++){
                    var tr = $('#temporaryProjectUpdatePanel .table-selfDefine tbody').find('.table-tr')
                    tr.eq(i).find('.selectPerson').attr('value', obj.data.details[i].user.id)
                    tr.eq(i).find('.selectPerson').val(obj.data.details[i].user.name)
                    tr.eq(i).find('.unitWage').val(obj.data.details[i].unitWage)
                    tr.eq(i).find('.days').val(obj.data.details[i].days)
                    tr.eq(i).find('.sumWage').text(obj.data.details[i].sumWage)
                }

                $('#temporaryProjectUpdatePanel-totalWage').text(obj.data.totalWage)
            }else{
                alert(obj.message)
            }
        },
        error: function (error) {
            console.log(error)
        }
    })
}
/*
提交外勤申请表/
 */
function submitUpdateApplyTable() {
    var updateID = $('#temporaryProjectUpdatePanel').attr('value')
    var date = $('#temporaryProjectUpdatePanel-workDate').val()
    date = date.split(' ')[0]
    date = date.replace(/年/g, '/')
    date = date.replace(/月/g, '/')
    date = date.replace(/日/g, '')
    date = date.replace(/\//g, '-')

    var makeTablePerson = $('#temporaryProjectUpdatePanel-makeTablePerson').attr('value')
    var department = $('#temporaryProjectUpdatePanel-applyDepartment').attr('value')
    if(!department){
        alert('出勤部门不能为空！')
        return
    }
    var applayUser = $('#temporaryProjectUpdatePanel-applyStaff').attr('value')
    if(!applayUser){
        alert('申请人不能为空！')
        return
    }
    var serviceCharge = $('#temporaryProjectUpdatePanel-serviceCharge').val()
    if(!serviceCharge){
        alert('服务费不能为空！')
        return
    }
    var auditor = $('#temporaryProjectUpdatePanel-auditor').attr('value')
    if(!auditor){
        alert('审核人不能为空！')
        return
    }
    var personNumber = $('#temporaryProjectUpdatePanel-personNumber').text()
    if(!personNumber){
        alert('出勤人次不能为空！')
        return
    }
    var content = $('#temporaryProjectUpdatePanel-content').val()

    var totalWage = $('#temporaryProjectUpdatePanel-totalWage').text()
    if(!totalWage){
        alert('总计金额不能为空！')
        return
    }
    var tr = $('#temporaryProjectUpdatePanel .table-selfDefine .table-tr')
    if(tr.length == 0){
        alert('请选择出勤人员！')
        return
    }
    var jsonArr = []
    for(var i = 0; i < tr.length; i++){
        var id = tr.eq(i).find('td').eq(1).find('.selectPerson').attr('value')
        if(i == 0){
            if(!id){
                alert('第一行人员不能为空！')
                return
            }
        }

        var json_ = {}
        if(id){
            json_['user'] = {
                "id": id
            }
            var unitWage = tr.eq(i).find('td').eq(2).find('input').val()
            json_['unitWage'] = parseFloat(unitWage).toFixed(2)
            var days = tr.eq(i).find('td').eq(3).find('input').val()
            json_['days'] = parseInt(days)
            var sumWage = tr.eq(i).find('td').eq(4).text()
            json_['sumWage'] = parseFloat(sumWage).toFixed(2)
            jsonArr.push(json_)
        }

    }
    var json = {
        "id":updateID,
        "date":date,
        "personNum":personNumber,
        "totalWage":totalWage,
        "serviceCharge":parseFloat(serviceCharge).toFixed(2),
        "content":content,
        "applicant": {
            "id":applayUser
        },
        "auditor": {
            "id":auditor
        },
        "operator": {
            "id":makeTablePerson
        },
        "department": {
            "id":department
        },
        "details": jsonArr
    }
    let myjson = JSON.stringify(json)
    console.log(json)
    $.ajax({
        url: ipPort + '/temporaryProjectHeader/update',
        contentType: 'application/json',
        data: myjson,
        dataType: 'json',
        type: 'post',
        success: function (obj) {
            if(obj.code == 0){
                alert('提交成功！')
            }else {
                alert(obj.message)
            }
        },
        error: function (error) {
            console.log(error)
        }
    })

}
/*
人员改变事件/
 */
function changePerson() {
    var tr = $('#temporaryProjectUpdatePanel .table-selfDefine .table-tr')
    var personNumber = 0
    for(var i = 0; i < tr.length; i++){
        var id = tr.eq(i).find('td').eq(1).find('.selectPerson').attr('value')
        if(id){
            personNumber++
        }
    }
    $('#temporaryProjectUpdatePanel-personNumber').text(personNumber)
}
/*
增加申请表内容/
 */
function addApplyContent() {
    index++
    var tbody = $('#temporaryProjectUpdatePanel .table-selfDefine tbody')
    var appendStr = "<tr class='table-tr'><td>" + index + "</td><td><input class='selectPerson' onclick='getAllStaff_one(1,this)' data-toggle='modal' data-target='#myModal-selectOneStaff'></td>" +
        "<td><input class='unitWage'></td><td><input class='days'></td><td class='sumWage'></td>" +
        "<td style='border-right: none'><a onclick='cleanRowApplyContent(this)'><img src='imgs/minus-r.png'></a></td></tr>"
    tbody.append(appendStr)
}
/*
清除申请表内容一行/
 */
function cleanRowApplyContent(thisObj) {
    $(thisObj).parent().parent().remove()
    index--
    var tr = $('.table-selfDefine').find('.table-tr')
    for(var i = 1; i <= tr.length; i++){
        tr.eq(i-1).find('td').eq(0).text(i)
    }
    changePerson()
}
/*
设置makeSureModal的value/
 */
function setMakeSureDeleteButtonValue(thisObj) {
    var td = $(thisObj).parent().parent().find('td')
    var id = td.eq(0).text()
    var applyUser = td.eq(1).attr('value')
    $('#myModal-makeSureDelete').attr('idValue', id)
    $('#myModal-makeSureDelete').attr('applyUserValue', applyUser)
}
/*
删除单个合同信息/
 */
function deleteApply() {
    var id = []
    id.push($('#myModal-makeSureDelete').attr('idValue'))
    var applyUser = $('#myModal-makeSureDelete').attr('applyUserValue')
    var urlStr = ipPort + '/temporaryProjectHeader/deleteByIdAndApplicant?ids='+ id + '&applicantId=' + applyUser
    $.ajax({
        url:urlStr,
        type:'post',
        success:function (obj) {
            if(obj.code == 0){
                alert('删除成功!')
                getAllTemporaryApply(currentPage)
            }
            else{
                alert(obj.message)
            }
        },
        error:function (error) {
            console.log(error)
        }
    })
}
/*
设置申请表详情Modal/
 */
function setTemporaryProjectApplyRecordModal(thisObj) {
    $('#makeTablePerson').text('')
    $('#workDate').text('')
    $('#department').text('')
    $('#applyUser').text('')
    $('#auditor').text('')
    $('#status').text('')
    $('#serviceCharge').text('')
    $('#personNumber').text('')
    $('#content').val('')
    $('.temporaryProjectManagerDetails-table-selfDefine').find('.table-tr').remove()
    $('#totalWage').text('')
    $('#note').text('')
    $('#auditor2').text('')
    $('#auditTime').text('')
    var id = $(thisObj).parent().parent().find('td').eq(0).text()
    $.ajax({
        url: ipPort + '/temporaryProjectHeader/getById?id=' + id,
        success: function (obj) {
            if(obj.code == 0){
                $('#makeTablePerson').text(obj.data.operator.name)
                if(flag_temporaryProjectManage){
                    $('#workDate').text(obj.data.date)
                    $('#serviceCharge').text(obj.data.serviceCharge)
                }
                else{
                    $('#workDate').text('******')
                    $('#serviceCharge').text('***')
                }
                $('#department').text(obj.data.department.name)
                $('#applyUser').text(obj.data.applicant.name)
                $('#auditor').text(obj.data.auditor.name)
                if(obj.data.status == 0){
                    $('#status').text('未审核')
                }else if(obj.data.status == 1){
                    $('#status').text('通过')
                    $('#note').text(obj.data.note)
                    $('#auditor2').text(obj.data.auditor.name)
                    $('#auditTime').text(obj.data.auditTime)
                }else if(obj.data.status == 2){
                    $('#status').text('未通过')
                    $('#note').text(obj.data.note)
                    $('#auditor2').text(obj.data.auditor.name)
                    $('#auditTime').text(obj.data.auditTime)
                }
                $('#personNumber').text(obj.data.personNum)
                $('#content').val(obj.data.content)
                var tbody = $('.temporaryProjectManagerDetails-table-selfDefine tbody')
                for(var i = 0; i < obj.data.details.length; i++){
                    var appendStr ="<tr class='table-tr'><td>" + (i+1) +"</td><td>" + obj.data.details[i].user.name +"</td>" +
                        "<td>" + obj.data.details[i].unitWage + "</td><td>" + obj.data.details[i].days +"</td>" +
                        "<td style='border-right: none'>" + obj.data.details[i].sumWage + "</td></tr>"
                    tbody.append(appendStr)
                }
                $('#totalWage').text(obj.data.totalWage)
            }else{
                alert(obj.message)
            }
        },
        error: function (error) {
            console.log(error)
        }
    })
}
/*
获取所有部门/
 */
function getAllDepartment() {
    $('#myModal-selectDepartment').modal('toggle')
    $('.selectDepartment-ul li').remove()
    $.ajax({
        url: ipPort + '/department/getAll',
        success:function (obj) {
            if(obj.code == 0){
                for(var j = 0; j < obj.data.length; j++){
                    var ul = $('.selectDepartment-ul')
                    var appendStr = '<li data-dismiss="modal" onclick="selectedOneDepartment(this)"><img src="imgs/tips_department_up.png" height="20px" style="margin-top: -2px;margin-right: 5px"><span ' + 'value="' + obj.data[j].id + '">' + obj.data[j].name + '</span></li>'
                    ul.append(appendStr)
                }
            }else{
                alert(obj.message)
            }
        },
        error:function (error) {
            console.log(error)
        }
    })
}
/*
选定部门/
 */
function selectedOneDepartment(thisObj) {
    $('#temporaryProjectUpdatePanel-applyDepartment').val( $(thisObj).find("span").text())
    $('#temporaryProjectUpdatePanel-applyDepartment').attr('value', $(thisObj).find("span").attr("value"))
}
/*************************************选取一个员工modal*****************************************/
/*
获取所有员工/
 */
function getAllStaff_one(str, thisObj = null) {
    currentRow = thisObj
    currentModal = str
    var staffInformationDepartmentA = $('.selectOneStaff-department-ul .selectOneStaff-department-li .departmentName-span')
    $.ajax({
        url:ipPort + '/department/getAll',
        dataType:'json',
        success:function (obj) {
            for(var i = 0; i < obj.data.length; i++){
                staffInformationDepartmentA.eq(i).parent().removeClass('hidden')
                staffInformationDepartmentA.eq(i).text(obj.data[i].name)
                staffInformationDepartmentA.eq(i).attr('value', obj.data[i].id)
                staffInformationDepartmentA.eq(i).parent().find('li').remove()
            }
            $.ajax({
                url:ipPort + '/user/getAll',
                dataType:'json',
                success:function (obj_) {
                    if(obj_.data.length != 0){
                        for(var j = 0; j < obj_.data.length; j++){
                            for(var m = 0; m < obj.data.length; m++){
                                if(obj_.data[j].department.id == obj.data[m].id){
                                    var staffUl = staffInformationDepartmentA.eq(m).parent().find('.selectOneStaff-staff-ul')
                                    var appendStr = '<li data-dismiss="modal" onclick="selectedOneStaff(this)"><img src="imgs/mine.png" height="20px" style="margin-top: -2px"><span ' + 'value="' + obj_.data[j].id + '">' + obj_.data[j].name + '</span></li>'
                                    staffUl.append(appendStr)
                                    break
                                }
                            }
                        }
                    }
                },
                error:function (error) {
                    console.log(error)
                }
            })
        },
        error:function (error) {
            console.log(error)
        }
    })
}
/*
通过姓名搜索/
 */
function searchOneByName_modal(thisObj) {
    var keyword = $(thisObj).parent().find('input').val()
    var type = $('#selectSearchOneWay-dropdownMenu').attr('value')
    if(keyword != ''){
        $.ajax({
            url:ipPort + '/user/search?type=' + type + '&keyword=' + keyword,
            dataType:'json',
            success:function (obj) {
                $('#form-selectOneStaff .selectOneStaff-department-ul').addClass('hidden')
                $('#form-selectOneStaff .selectOneStaff-staff-ul2').removeClass('hidden')
                var staffUl = $('#form-selectOneStaff').find('.selectOneStaff-staff-ul2')
                staffUl.find('li').remove()
                for(var i = 0; i < obj.data.length; i++){
                    var appendStr = '<li data-dismiss="modal" onclick="selectedOneStaff(this)"><img src="imgs/mine.png" height="20px" style="margin-top: -2px"><span ' + 'value="' + obj.data[i].id + '">' + obj.data[i].name + '</span></li>'
                    staffUl.append(appendStr)
                }
            },
            error:function (error) {
                console.log(error)
            }
        })
    }
}
/*
选定人员/
 */
function selectedOneStaff(thisObj) {
    if(currentModal == 0){
        $('#temporaryProjectUpdatePanel-applyStaff').val( $(thisObj).find("span").text())
        $('#temporaryProjectUpdatePanel-applyStaff').attr('value', $(thisObj).find("span").attr("value"))
    }
    else if(currentModal == 1){
        $(currentRow).val( $(thisObj).find("span").text())
        $(currentRow).attr('value', $(thisObj).find("span").attr("value"))

        changePerson()
    }
    else if(currentModal == 2){
        $('#temporaryProjectUpdatePanel-auditor').val( $(thisObj).find("span").text())
        $('#temporaryProjectUpdatePanel-auditor').attr('value', $(thisObj).find("span").attr("value"))
    }
}
/******************************************************************************/

/**********************************************************888/
 /*
 上一页/
 */
function previousPage() {
    var currentPage_ = $('.currentPage').text()
    if(currentPage_ == 1){
        alert("已经是第一页！")
        return
    }
    currentPage--
    if(currentPage < 0){
        currentPage = 0
    }
    if(currentSearch == -1){
        getAllTemporaryApply(currentPage)
    }else  if(currentSearch == -2){
        searchByStatus(currentPage)
    }
}
/*
下一页/
 */
function nextPage() {
    var currentPage_ = $('.currentPage').text()
    var totalPage_ = $('.totalPage').text()
    if(currentPage_ == totalPage_){
        alert("已经是最后一页！")
        return
    }
    currentPage++
    if(currentSearch == -1){
        getAllTemporaryApply(currentPage)
    }else  if(currentSearch == -2){
        searchByStatus(currentPage)
    }
}
/*
跳转页/
 */
function skipPage() {
    var skipPage_ = parseInt($('.skipPage').val())
    var totalPage_ = parseInt($('.totalPage').text())
    if(skipPage_ - totalPage_ > 0){
        alert("没有此页！")
        return
    }
    if(skipPage_ < 1){
        alert("没有此页！")
        return
    }
    currentPage = skipPage_ - 1
    if(currentSearch == -1){
        getAllTemporaryApply(currentPage)
    }else  if(currentSearch == -2){
        searchByStatus(currentPage)
    }
}